package com.basker.pisces.concurrent.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import com.basker.pisces.concurrent.counter.ICounterManager;
import com.basker.pisces.concurrent.counter.LocalCounterManager;
import com.basker.pisces.config.Constants;

@Configuration
public class LocalCounterManagerConfiguration {

    private static final String DEFAULT_COUNTER_MANAGER = Constants.DEFAULT_COUNTER_MANAGER;

    /**
     * 如果不存在其他{@value #DEFAULT_COUNTER_MANAGER}的ICounterManager,则默认计数器管理器为{@link LocalCounterManager}
     *
     * @return
     */
    @Bean(name = DEFAULT_COUNTER_MANAGER)
    @Primary
    @ConditionalOnMissingBean(name = DEFAULT_COUNTER_MANAGER)
    public ICounterManager localCounterManager() {
        return new LocalCounterManager(DEFAULT_COUNTER_MANAGER);
    }
}
